<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑代理商</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all" />
	<style>
		.layui-form{
			margin: 10px;
		}
	</style>
</head>
<body class="childrenBody">
<form class="layui-form">
	<div class="layui-form-item">
		<label class="layui-form-label">代理商名称</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" lay-verify="required" name="name" placeholder="请输入代理商名称">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">联系人</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="linkman" lay-verify="required" placeholder="请输入联系人">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">手机号码</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="phone" lay-verify="required||phone" placeholder="请输入手机号码">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">固定电话</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="landline" lay-verify="required" placeholder="请输入固定电话">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">账号</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="username" lay-verify="required" placeholder="请输入登录账号" autocomplete="off" readonly="readonly">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">密码</label>
		<div class="layui-input-block">
			<input type="password" class="layui-input" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="editAgents">立即提交</button>
			<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

<script type="text/javascript" src="/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/plugins/layui/layui.js"></script>
<script type="text/javascript">

layui.config({
    base: '/js/admin/'
}).extend({
    ajaxExtention: 'ajaxExtention',
    $tool: 'tool'
}).use(['form', 'layer', 'jquery', 'ajaxExtention', '$tool'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery,
        $tool = layui.$tool;
     initFormInfo();
    /**
     * 初始化表单信息
     * */
     function initFormInfo() {
        var queryArgs = $tool.getQueryParam();//获取查询参数
        var id = queryArgs['id'];
        var url = '/agents/getById/'+id;
        $.ajax({
            url:url,
            method:"GET",
            success:function (data) {
                var obj = data.data;
                $("input[name='name']").val(obj.name);
                $("input[name='linkman']").val(obj.linkman);
                $("input[name='phone']").val(obj.phone);
                $("input[name='landline']").val(obj.landline);
                $("input[name='username']").val(obj.username);
                $("input[name='password']").val(obj.password);
                form.render();
            }
        });
    }
  
    /**
     * 表单提交
     * */
     form.on("submit(editAgents)", function (data) {
        var queryArgs = $tool.getQueryParam();//获取查询参数
        var id = queryArgs['id'];
        var name = data.field.name;
         var linkman = data.field.linkman;
         var phone = data.field.phone;
         var landline = data.field.landline;
         var username = data.field.username;
         var password = data.field.password;


        //请求
        var url ='/agents';
        var req = {
            id:id,
            name: name,
            linkman: linkman,
            phone: phone,
			landline:landline,
            username:username,
			password:password

        };
        $.ajax({
            url: url,
            contentType:"application/json;charset=UTF-8",
            data: JSON.stringify(req),
            method: "PUT",
            success: function (data) {
                if(data.code==2000){
                	 layer.msg("代理商信息更新成功！", function () {
                         layer.closeAll("iframe");
                         parent.location.reload();
                     });
                }else {
                    layer.msg(data.msg)
				}
               
            }
           
        });

        return false;
    }) 

});

</script>
</body>
</html>

